<%@ include file="/en/jsp/static.jsp" %>
<%@ taglib uri="/linuxbox/bbs.tld" prefix="bbs" %>
<%@ page import="linuxbox.bbs.logic.*" %>
<%
  String TOPIC_COUNT = (String)request.getAttribute("TOPIC_COUNT");
  String CAT_ID = (String)request.getAttribute("CAT_ID");
  String CAT_NAME = (String)request.getAttribute("CAT_NAME");
  String PAGE_SIZE = (String)request.getAttribute("PAGE_SIZE");
  String PAGES = (String)request.getAttribute("PAGES");
  String PAGE_NO = (String)request.getAttribute("PAGE_NO");
  String PREV = (String)request.getAttribute("PREV");
  String NEXT = (String)request.getAttribute("NEXT");

  int curPage = 0;
  if (PAGE_NO != null)
    curPage = Integer.parseInt(PAGE_NO) - 1;
  int totalPage = 1;
  if (PAGES != null)
    totalPage = Integer.parseInt(PAGES);

%>

<jsp:include page="/en/jsp/header.jsp" flush="true"/>

<script Language="JavaScript">

function onChangeCategory()
{
    document.theForm.submit();
}
</SCRIPT>


<table width="100%" height=26 align=middle border=0 cellpadding=0 cellspacing=0 bgcolor="#f4f4f4" style="font-size:16px;color:#d05000">
  <tr>
    <td>
      &nbsp;<img src="<%=BoxStatic.imageDir%>itemball.jpg" width=14 height=15 border=0 align="absmiddle">
      <b><%=boxName%> - BBS[<%=CAT_NAME%>] Contents</b>
    </td>
<FORM action="<%=BoxStatic.servletDir%>BbsContentAction" method="POST" name="theForm" >
    <td ALIGN="right" valign="top">
      <a href="<%=BoxStatic.jspDir%>bbs/BbsNewList.jsp">New List</a>&nbsp;|&nbsp;

      <a href="<%=BoxStatic.jspDir%>bbs/BbsQueryAll.jsp">Search</a>

      &nbsp;|&nbsp;View Category
        <SELECT NAME="CAT_ID" onchange="onChangeCategory()">
          <bbs:BbsCatList listType="list" selected="<%=CAT_ID%>" />
        </select>
    </td>
</FORM>
  </tr>
</table>

<hr width="100%" color=#E06000 align=left>

<table width="100%" border=0 cellpadding=0 cellspacing=0>
  <tr><td>
    <table width="100%" border=0 cellpadding=0 cellspacing=0>
      <tr>
        <td>
          <input type="button" value="New..." onclick="window.location='<%=BoxStatic.servletDir%>BbsProposeFormAction?CAT_ID=<%=CAT_ID%>'" >
        </td>
        <td align=center valign="middle">
          Total <%=TOPIC_COUNT%> Topics
        </td>
        <td align=right  valign="middle">
          Showing page <%=curPage+1%> of <%=totalPage%> &nbsp;|&nbsp;
          <%
            if (curPage >0 )
            {
              out.print("<a href=\""+BoxStatic.servletDir+"/BbsContentAction?CAT_ID="+CAT_ID+"&PAGE_NO=1\">First</a>&nbsp;|&nbsp;");
              out.print("<a href=\""+BoxStatic.servletDir+"/BbsContentAction?CAT_ID="+CAT_ID+"&PAGE_NO="+curPage+"\">Prev</a>&nbsp;|&nbsp;");
            }
            else
            {
              out.print("First&nbsp;|&nbsp;Prev&nbsp;|&nbsp;");
            }
            if (curPage < totalPage -1 )
            {
              out.print("<a href=\""+BoxStatic.servletDir+"/BbsContentAction?CAT_ID="+CAT_ID+"&PAGE_NO="+(curPage+2)+"\">Next</a>&nbsp;|&nbsp;");
              out.print("<a href=\""+BoxStatic.servletDir+"/BbsContentAction?CAT_ID="+CAT_ID+"&PAGE_NO="+(totalPage)+"\">Last</a>");
            }
            else
            {
              out.print("Next&nbsp;|&nbsp;Last");
            }
          %>
        </td>
      </tr>
      <tr>
        <form action="<%=BoxStatic.jspDir%>bbs/BbsQuery.jsp" method=post>
        <td  valign="middle" align=right colspan=3>
            <input type="hidden" name="CAT_ID" value="<%=CAT_ID%>">
            <input type="hidden" name="CAT_NAME" value="<%=CAT_NAME%>">
            <input type="text" size="20" name="QUERY_TEXT">
            <input type="submit" name="OK" value="Search">
        </td>
        </form>
      </tr>
    </table>
  </td></tr>
<%
      if (!TOPIC_COUNT.equals("0"))
      {
%>
  <tr><td>
    <TABLE cellSpacing=1 cellPadding=0 width="100%" border=0 bgColor=#dddddd>
<%
        try {
          int iCurrentSize = Integer.parseInt(PAGE_SIZE);
          int catID = Integer.parseInt(CAT_ID);
          int pageNo = Integer.parseInt(PAGE_NO);

          BbsManager bm = BbsManager.getInstance();
          long lCurrentTopicID = bm.getRequestTopicID((long)((pageNo - 1) * BbsManager.PAGE_SIZE), catID);

          for (int i = 0; i < iCurrentSize; i++) { %>
            <tr <% if ((i % 2) == 0) out.print("bgcolor=#f0f0f0"); %>>
              <td>
                <bbs:ShowTopic topicID="<%=Long.toString(lCurrentTopicID)%>" catID="<%=CAT_ID%>"/>
              </td>
            </tr>
          <%
            lCurrentTopicID = bm.getPrevTopic(lCurrentTopicID, catID);
          }
        } catch (Exception e) {
        }
    %>
    </table>
  </td></tr>
  <tr><td>
    <table border=0 width="100%" cellpadding=0 cellspacing=0>
      <tr>
        <td>
          <input type="button" value="New..." onclick="window.location='<%=BoxStatic.servletDir%>BbsProposeFormAction?CAT_ID=<%=CAT_ID%>'" >
        </td>
        <td align=center valign="middle">
          Total <%=TOPIC_COUNT%> Topics
        </td>
        <td align=right  valign="middle">
          Showing page <%=curPage+1%> of <%=totalPage%> &nbsp;|&nbsp;
          <%
            if (curPage >0 )
            {
              out.print("<a href=\""+BoxStatic.servletDir+"/BbsContentAction?CAT_ID="+CAT_ID+"&PAGE_NO=1\">First</a>&nbsp;|&nbsp;");
              out.print("<a href=\""+BoxStatic.servletDir+"/BbsContentAction?CAT_ID="+CAT_ID+"&PAGE_NO="+curPage+"\">Prev</a>&nbsp;|&nbsp;");
            }
            else
            {
              out.print("First&nbsp;|&nbsp;Prev&nbsp;|&nbsp;");
            }
            if (curPage < totalPage -1 )
            {
              out.print("<a href=\""+BoxStatic.servletDir+"/BbsContentAction?CAT_ID="+CAT_ID+"&PAGE_NO="+(curPage+2)+"\">Next</a>&nbsp;|&nbsp;");
              out.print("<a href=\""+BoxStatic.servletDir+"/BbsContentAction?CAT_ID="+CAT_ID+"&PAGE_NO="+(totalPage)+"\">Last</a>");
            }
            else
            {
              out.print("Next&nbsp;|&nbsp;Last");
            }
          %>
        </td>
      </tr>
    </table>
  </td></tr>
<%	    }
    %>

</table>
<hr width="100%" color=#E06000 align=left>

<jsp:include page="/en/jsp/footer.jsp" flush="true"/>
